package org.pms.demo.webservice.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.pms.demo.webservice.content.PmsContent;
import org.pms.demo.webservice.exception.IMReadException;
import org.pms.demo.webservice.service.SessionVersionService;
import org.pms.demo.webservice.utils.ProjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

/**
 * Created by xusaike on 17/10/16.
 */
@Component
@Path("v{version}/session")
public class SessionVersionRestController {

    @Autowired
    private SessionVersionService sessionVersionService;
    @Autowired
    private SessionDAO sessionDAO;
    @GET
    @Path("/list")
    @RequiresPermissions("session:view")
    public String list() {

        try{
            return sessionVersionService.getSessionList();
        }catch (Exception e){
            IMReadException.printf(e);
        }
        return ProjectUtils.getErrorMsg("error");
    }


    @GET
    @Path("/{sessionId}/forceLogout")
    public String forceLogout(@PathParam("sessionId")String sessionId
            ) {
        try {

            return sessionVersionService.forceLogout(sessionId);

        } catch (Exception e) {
            IMReadException.printf(e);
        }
        return ProjectUtils.getErrorMsg("error");
    }


}
